package com.example.demo.event;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: Bin.L
 * @date: 2021/4/9 0009 10:02
 * @Description:
 */
@Service
@Slf4j
public class SendMessageService implements ApplicationEventPublisherAware {

    private ApplicationEventPublisher aep;

    @Value("#{'${number.arrays}'.split(',')}")
    private List<String> arrays;

    @Override
    public void setApplicationEventPublisher(ApplicationEventPublisher aep) {
        this.aep = aep;
    }

    public void sendMsg(String message) {
        // 执行发送逻辑
        System.out.println(arrays);

        aep.publishEvent(new MessageEvent(this, message));
    }
}
